<?php



namespace App\Http\Controllers\Backend1;


use App\Services\Business\Models\ImageCategory;
use Illuminate\Http\Request;

class ImageCategoryController extends BaseController
{

    public function tree()
    {
        $list = ImageCategory::all();
        $categories = $this->makeTree($list,0);
        return  $this->successData(compact('categories'));
    }

    function makeTree($data, $pid = 0)
    {
        $tree = array();
        foreach ($data as $item) {
            if ($item->parent_id == $pid) {
                $children = $this->makeTree($data, $item->id);
                if (!empty($children)) {
                    $item->children = $children;
                }
                $tree[] = $item;
            }
        }
        return $tree;
    }




}





